package com.xyd.servlet;

import com.xyd.entity.Order;
import com.xyd.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/OrderUpdateByEoIdServlet")
public class OrderUpdateByEoIdServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        long id=Long.parseLong(request.getParameter("id"));
        String name= request.getParameter("name");
        String adress=request.getParameter("adr");
        String time=request.getParameter("time");
        String sate=request.getParameter("state");
        String money=request.getParameter("money");
        double cost=Double.parseDouble(request.getParameter("cost"));
        OrderServiceImpl orderService = new OrderServiceImpl();
        Order order = new Order();
        order.setEoId(id);
        order.setEoUsername(name);
        order.setEoUserAddress(adress);
        order.setEoCreateTime(time);
        order.setEoType(moneyType(money));
        order.setEoCost(cost);
        order.setEoStatus(orderState(sate));
        int a=orderService.changeOrderByEoId(order);
    }
    public int moneyType(String x){
        switch (x){
            case "货到支付":
                return 1;
            default:
                return 2;
        }
    }
    public int orderState(String x){
        switch (x){
            case "下单":
                return 1;
            case "审核通过":
                return 2;
            case "配货":
                return 3;
            case "发货中":
                return 4;
            default:
                return 5;

        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
